﻿Imports System.Data
Partial Class Egresados_Estudios_Estudios
    Inherits PaginaComun

    Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
        Dim obj As New Estudios
        obj.INSTITUCION = TxtEmp.Text
        obj.TIPO_ESTUDIO = CmbTipo.SelectedValue
        obj.TITULO_OBTENIDO = TxtJefe.Text
        obj.DURACION = TxtDur.Text
        obj.FECHA_INGRESO = DtpFecI.SelectedDate
        obj.FECHA_GRADO = DtpFecR.SelectedDate
        obj.PERIODO = CmbPeriodo.SelectedValue
        obj.IDPK = Me.Pk1
        Select Case Me.Oper
            Case "Nuevo"
                MsgModalPanel.Text = obj.Insert
                If obj.lErrorG = False Then
                    ImgRst.ImageUrl = "~/imagenes/good.png"
                Else
                    ImgRst.ImageUrl = "~/imagenes/error.png"
                End If
                ModalPopup.Show()
            Case "Editar"
                MsgModalPanel.Text = obj.Update
                If obj.lErrorG = False Then
                    ImgRst.ImageUrl = "~/imagenes/good.png"
                Else
                    ImgRst.ImageUrl = "~/imagenes/error.png"
                End If
                ModalPopup.Show()
        End Select
        Me.GridView1.DataBind()
        Me.MultiView1.ActiveViewIndex = 1
    End Sub

    Sub limpiar()
        TxtEmp.Text = ""
        TxtJefe.Text = ""
        DtpFecI.SelectedDate = Today
        DtpFecR.SelectedDate = Today
        TxtDur.Value = 0
    End Sub

    Protected Sub ImageButton2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton2.Click
        Me.MultiView1.ActiveViewIndex = 1
    End Sub

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        Dim obj As New Estudios
        Select Case e.CommandName
            Case "Editar"
                Me.Oper = "Editar"
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)
                GridView1.SelectedIndex = index
                Dim dt As DataTable = obj.GetbyPK(GridView1.DataKeys(index).Values(0).ToString())
                If dt.Rows.Count > 0 Then
                    Me.TxtEmp.Text = dt.Rows(0)("Institucion").ToString
                    Me.TxtDur.Text = dt.Rows(0)("Duracion").ToString
                    Me.TxtJefe.Text = dt.Rows(0)("Titulo_Obtenido").ToString
                    Me.DtpFecI.SelectedDate = dt.Rows(0)("Fecha_Ingreso").ToString
                    Me.DtpFecR.SelectedDate = dt.Rows(0)("Fecha_Grado").ToString
                    Me.CmbTipo.SelectedValue = dt.Rows(0)("Tipo_Estudio").ToString
                    Me.CmbPeriodo.SelectedValue = dt.Rows(0)("Periodo").ToString
                    Me.Pk1 = dt.Rows(0)("Id").ToString
                    Me.MultiView1.ActiveViewIndex = 0
                End If
            Case "Eliminar"
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)
                GridView1.SelectedIndex = index
                Me.Pk1 = GridView1.DataKeys(index).Values(0).ToString()
                Me.ModalPopupExtender1.Show()
        End Select
    End Sub

    Protected Sub ImageButton3_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton3.Click
        Me.Oper = "Nuevo"
        limpiar()
        Me.MultiView1.ActiveViewIndex = 0
    End Sub

    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim obj As New Estudios
        MsgModalPanel.Text = obj.Delete(Me.Pk1)
        If obj.lErrorG = False Then
            ImgRst.ImageUrl = "~/imagenes/good.png"
        Else
            ImgRst.ImageUrl = "~/imagenes/error.png"
        End If
        ModalPopup.Show()
        GridView1.DataBind()
    End Sub
End Class
